package com.youlu.campus.web.notify;


import com.kuaidi100.sdk.response.SubscribeResp;
import com.youlu.campus.service.notify.KuaiDi100Service;
import com.yuelin.infrastructure.quantum.common.QResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

@Slf4j
@RestController
public class KuaiDi100Controller {

    @Autowired
    private KuaiDi100Service kuaiDi100Service;


    /**
     * 物流信息回调接口
     *
     * @param request
     * @return
     */
    @PostMapping("/public/kuaidi100/callback")
    public SubscribeResp kuaiDi100CallBack(HttpServletRequest request) {
        return kuaiDi100Service.callBackUrl(request);
    }

    /**
     * 地图轨迹
     *
     * @param number
     * @param orderNo
     * @param shippingTime
     * @return
     */
    @PostMapping("/public/kuaidi100/track")
    public QResult queryTrackMap(@RequestParam String number, @RequestParam String orderNo,
                                 @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date shippingTime) {
        return QResult.success(kuaiDi100Service.queryTrackMap(number, orderNo, shippingTime));
    }

    @GetMapping("/public/kuaidi100/poll-map")
    public QResult subscribepollMap(@RequestParam String number, @RequestParam String orderNo) {
        kuaiDi100Service.testInitPollMap(number, orderNo);
        return QResult.success(null);
    }


}
